package astudy.bytecode;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.net.URL;
import java.net.URLDecoder;
import java.security.ProtectionDomain;

import org.apache.commons.io.IOUtils;

class Transformer implements ClassFileTransformer {

    public byte[] transform(ClassLoader l, String className, Class<?> c,
            ProtectionDomain pd, byte[] b) throws IllegalClassFormatException {
    	
    	System.out.println(className);
        
		URL url = ClassLoader.getSystemResource("StringBuilder.class");
		try {
			File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
            InputStream is = new FileInputStream(file);
            return IOUtils.toByteArray(is);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
    }
}
